home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / Script Builder 1.0 / Helper Source / GOSAScriptComponent.cp < prev    next >
Encoding:
Text File  |  1995-12-12  |  2.0 KB  |  100 lines  |  [TEXT/CWIE]

  1. /***
  2.  * GOSAScriptComponent.cp
  3.  *
  4.  *  A component that does scripting
  5.  *
  6.  *  Gordon Watts (gwatts@fnal.fnal.gov) © 1995 As Is!
  7.  ***/
  8.  
  9. #include "GOSAScriptComponent.h"
  10.  
  11. #ifndef kComponentNotFound
  12. #define kComponentNotFound -1
  13. #endif
  14.  
  15. GOSAScriptComponent *GOSAScriptComponent :: mDefaultScriptComponent = 0;
  16.  
  17. /**
  18.  * GetDefaultComponent
  19.  *
  20.  *  Return the default component.  This guy is only opened once...
  21.  *
  22.  **/
  23. GOSAScriptComponent * GOSAScriptComponent :: GetDefaultComponent (void)
  24. {
  25.     if (!mDefaultScriptComponent)
  26.         mDefaultScriptComponent = new GOSAScriptComponent;
  27.     
  28.     return mDefaultScriptComponent;
  29. }
  30.  
  31. /**
  32.  * GOSAScripComponent
  33.  *
  34.  *  Open the component -- default
  35.  *
  36.  **/
  37. GOSAScriptComponent :: GOSAScriptComponent (void)
  38. {
  39.     CommonInit ((OSType) 0, (OSType) 0);
  40. }
  41.  
  42. GOSAScriptComponent :: GOSAScriptComponent (OSType subType, OSType manuf)
  43. {
  44.     CommonInit (subType, manuf);
  45. }
  46.  
  47. /**
  48.  * ~GOSAScriptComponent
  49.  *
  50.  *  Close off the component, if open.
  51.  *
  52.  **/
  53. GOSAScriptComponent :: ~GOSAScriptComponent (void)
  54. {
  55.     if (mScriptComponent)
  56.         CloseComponent(mScriptComponent);
  57. }
  58.  
  59. /**
  60.  * CommonInit
  61.  *
  62.  *  Get the damm component.
  63.  *
  64.  **/
  65. void GOSAScriptComponent :: CommonInit (OSType subtype, OSType manuf)
  66. {
  67.     mScriptComponent = 0;
  68.  
  69.     /**
  70.      ** See if we can't find the component -- take the first one
  71.      ** there.
  72.      **/
  73.  
  74.     ComponentDescription     descr;
  75.     Component                aComponent;
  76.  
  77.     descr.componentType         = kOSAComponentType;
  78.     descr.componentSubType      = subtype;
  79.     descr.componentManufacturer = manuf;
  80.     descr.componentFlags        = kOSASupportsCompiling + 
  81.                                   kOSASupportsGetSource + 
  82.                                   kOSASupportsConvenience + 
  83.                                   kOSASupportsEventHandling;
  84.     descr.componentFlagsMask    = descr.componentFlags;
  85.     
  86.     aComponent = FindNextComponent(nil, &descr);
  87.  
  88.     if (!aComponent)
  89.         ThrowOSErr_(kComponentNotFound);
  90.     
  91.     /**
  92.      ** Ok -- if we have the component, then we can open it.
  93.      **/
  94.  
  95.     mScriptComponent = OpenComponent (aComponent);
  96.     
  97.     if (!mScriptComponent)
  98.         ThrowOSErr_(kComponentNotFound);
  99. }
  100.